import java.util.Arrays;
import java.util.Random;

public class Text {
    public static void OrderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            //升序
            array[i] = i;
            //降序
//            array[i] = array.length - i;
        }
    }

    public static void NorOrderArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            //随机
            array[i] = random.nextInt(array.length);
        }
    }

    public static void getInsertTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.InsertSotrt(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("直接插入算法:" + (endTime - startTime));
    }

    public static void getshellTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("希尔排序算法:" + (endTime - startTime));
    }

    public static void getselectTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("选择排序算法:" + (endTime - startTime));
    }

    public static void getselectOptimizationTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.selectSortOptimization(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("选择排序算法:" + (endTime - startTime));
    }

    public static void getHeapTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("堆排序算法:" + (endTime - startTime));
    }

    public static void getquickTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("快速排序算法:" + (endTime - startTime));
    }

    public static void getmergeTimestamp(int[] array){
        long startTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis(); // 获取毫秒级时间戳
        System.out.println("快速排序算法:" + (endTime - startTime));
    }

    public static void ComplexSort () {
        int[] array = new int[10_0000];
        //OrderArray(array);
        NorOrderArray(array);

        //插入算法
//        getInsertTimestamp(array);
        //希尔排序
        getshellTimestamp(array);
        // 选择排序
//        getselectTimestamp(array);
        // 选择排序优化后
//        getselectOptimizationTimestamp(array);

        getHeapTimestamp(array);
        //快速排序
        getquickTimestamp(array);
        //归并排序
        getmergeTimestamp(array);
    }

    public static void main(String[] args) {
        SimpleSort();
//        ComplexSort();
    }

    public static void SimpleSort() {
        int[] array = { 10,20,1,3,2,6,9 };
//        int[] array = { 5,2,3,1 };
//        int[] array = { 7,3,2,4,1 };


        Sort sort = new Sort();
//        sort.InsertSotrt(array);

        //Sort.shellSort(array);
//        Sort.selectSort(array);
        System.out.println("原数组：   "+Arrays.toString(array));

        Sort.countSort(array);

//        System.out.println(Arrays.toString(array));
        System.out.println("排序后数组："+Arrays.toString(array));
    }



}
